package videoGrabber;

import java.util.Vector;

import javax.media.CaptureDeviceInfo;
import javax.media.CaptureDeviceManager;
import javax.media.Format;
import javax.media.MediaLocator;

import view.Gui;

/**
 * Provides the access to the capture device
 * @author	Daniel Mohr, Daniela Grammlich
 */
public class CamAccess
{
	/**
	 * Information about the used device
	 */
	private CaptureDeviceInfo deviceInfo;
	/**
	 * The media locator
	 */
	private MediaLocator locator = null;
	/**
	 * The used format
	 */
	private Format[] format = null;
	/**
	 * The video grabber
	 */
	VideoGrabber videoGrabber;
	/**
	 * The graphical user interface
	 */
	Gui gui;

	/**
	 * Constructor. Searches and initializes the capture device
	 */
	public CamAccess()
	{
		//Capture Device "vfw:Microsoft WDM Image Capture (Win32):0"
		//Media Locator "vfw://0" */
		Vector<?> deviceList = (Vector<?>)CaptureDeviceManager.getDeviceList(null).clone();
		if(deviceList == null)
		{
			System.out.println("Error: No Device found, programm aborted");
			this.videoGrabber.playerClose();
			System.exit(0);
		}
		if(deviceList.size() == 0)
		{
			System.out.println("Error: No Device found, programm aborted");
			this.videoGrabber.playerClose();
			System.exit(0);
		}
		if(deviceList.size() > 0)
		{
			this.deviceInfo = (CaptureDeviceInfo) deviceList.elementAt(0);
			format = deviceInfo.getFormats();
			this.locator = deviceInfo.getLocator();
		}
		CaptureDeviceManager.addDevice(deviceInfo);
	}
	
	/**
	 * getter for <code>{@link #locator}</code>
	 */
	public MediaLocator getMediaLocator()
	{
		return this.locator;
	}

	/**
	 * getter for <code>{@link #deviceInfo}</code>
	 */
	public CaptureDeviceInfo getCaptureDevice()
	{
		return this.deviceInfo;
	}
	
	/**
	 * getter for <code>{@link #format}</code>
	 */
	public Format[] getFormat()
	{
		return this.format;
	}
	
}
